using MediatR;
using B.S.XZYData.ErrorCode;
using System;
using System.Collections.Generic;

namespace B.S.XZYData.Api.Read.Application.Command.WorkReport
{
    /// <summary>
    /// 查询报工分页命令
    /// </summary>
    public class QueryWorkReportCommand : IRequest<ApiResult<WorkReportPageResult>>
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; set; } = 1;

        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { get; set; } = 30;

        /// <summary>
        /// 工单业务编码
        /// </summary>
        public string? WorkOrderCode { get; set; }

        /// <summary>
        /// 工序名称
        /// </summary>
        public string? ProcessName { get; set; }

        /// <summary>
        /// 产品编码
        /// </summary>
        public string? ProductCode { get; set; }

        /// <summary>
        /// 创建时间开始
        /// </summary>
        public DateTime? CreateTimeStart { get; set; }

        /// <summary>
        /// 创建时间结束
        /// </summary>
        public DateTime? CreateTimeEnd { get; set; }

        /// <summary>
        /// 工序状态（0=未开始,1=进行中,2=已完成）
        /// </summary>
        public B.S.XZYData.Domain.ZSH.ProcessStatusEnum? ProcessStatus { get; set; }

        /// <summary>
        /// 排序字段
        /// </summary>
        public string SortField { get; set; } = "Id";

        /// <summary>
        /// 排序方向（asc/desc）
        /// </summary>
        public string SortDirection { get; set; } = "desc";
    }

    /// <summary>
    /// 报工分页结果
    /// </summary>
    public class WorkReportPageResult
    {
        /// <summary>
        /// 数据列表
        /// </summary>
        public List<WorkReportDto> Data { get; set; } = new List<WorkReportDto>();

        /// <summary>
        /// 总数
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// 页码
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { get; set; }
    }

    /// <summary>
    /// 报工DTO
    /// </summary>
    public class WorkReportDto
    {
        public int Id { get; set; }
        public string? WorkOrderCode { get; set; }
        public string? ProcessName { get; set; }
        public string? ProductCode { get; set; }
        public string? ProductNo { get; set; }
        public string? ProductName { get; set; }
        public string? ProductSpec { get; set; }
        public string? ProcessStatus { get; set; }
        public string? Producer { get; set; }
        public int ReportQty { get; set; }
        public string? Unit { get; set; }
        public int GoodQty { get; set; }
        public int DefectiveQty { get; set; }
        public string? ProcessProgress { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime? EndTime { get; set; }
        public decimal ReportHours { get; set; }
        public int ReportMinutes { get; set; }
        public decimal StandardEfficiency { get; set; }
        public decimal ActualEfficiency { get; set; }
        public decimal ComplianceRate { get; set; }
        public string? PricingMethod { get; set; }
        public decimal WageUnitPrice { get; set; }
        public decimal EstimatedWage { get; set; }
        public string? ApprovalStatus { get; set; }
        public string? Approver { get; set; }
        public DateTime CreateTime { get; set; }
        public string? CreatorName { get; set; }
        public DateTime? ModifyTime { get; set; }
        public string? ModifierName { get; set; }
        
        /// <summary>
        /// 不良品项列表
        /// </summary>
        public List<WorkReportDefectiveItemDto> DefectiveItems { get; set; } = new List<WorkReportDefectiveItemDto>();
    }

    /// <summary>
    /// 报工不良品项DTO
    /// </summary>
    public class WorkReportDefectiveItemDto
    {
        /// <summary>
        /// 主键
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 关联报工主表Id
        /// </summary>
        public int WorkReportId { get; set; }

        /// <summary>
        /// 不良品项编码
        /// </summary>
        public string DefectiveCode { get; set; } = string.Empty;

        /// <summary>
        /// 不良品数量
        /// </summary>
        public int DefectiveQty { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 创建人姓名
        /// </summary>
        public string? CreatorName { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? ModifyTime { get; set; }

        /// <summary>
        /// 最后修改人姓名
        /// </summary>
        public string? ModifierName { get; set; }
    }
} 